package basic.study.wantOffer.chapter6;

import java.util.Arrays;

/**
 * @ClassName Problem61
 * @Description 扑克牌的顺子
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/14 21:01
 * @Version 1.0
 */
public class Problem61 {
    public boolean isContinuous(int[] numbers) {
        if (numbers == null || numbers.length == 0) {
            return false;
        }
        Arrays.sort(numbers);
        int numberOf0 = 0;
        int numberOfGap = 0;
        for (int i = 0; i < numbers.length; i++) {
            if (numbers[i] == 0) {
                numberOf0 ++;
            }
        }
        int small = numberOf0;
        int big = numberOf0 + 1;
        while (big < numbers.length) {
            if (numbers[small] == numbers[big]) {
                return false;
            }
            numberOfGap += numbers[big++] - numbers[small++] - 1;
        }
        if (numberOfGap <= numberOf0) {
            return true;
        }
        return false;
    }
}
